package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.EngineerProject;
import com.shrcl.engineerprocess.domain.EngineerProjectCriteria;
import com.shrcl.engineerprocess.domain.EngineerProjectStatus;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;

public class EngineerProjectCriteriaImpl extends HQLBasedPagedQueryCriteria<EngineerProject> implements EngineerProjectCriteria {
  private String info;
  
  public String getInfo() {
    return this.info;
  }
  
  public EngineerProjectCriteria setInfo(final String info) {
    this.info = info;
    return this;			
    
  }
  
  private EngineerProjectStatus excludedstatus;
  
  public EngineerProjectStatus getExcludedstatus() {
    return this.excludedstatus;
  }
  
  public EngineerProjectCriteria setExcludedstatus(final EngineerProjectStatus excludedstatus) {
    this.excludedstatus = excludedstatus;
    return this;			
    
  }
  
  private Engineer projectManager;
  
  public Engineer getProjectManager() {
    return this.projectManager;
  }
  
  public EngineerProjectCriteria setProjectManager(final Engineer projectManager) {
    this.projectManager = projectManager;
    return this;			
    
  }
  
  private Engineer stakeHolder;
  
  public Engineer getStakeHolder() {
    return this.stakeHolder;
  }
  
  public EngineerProjectCriteria setStakeHolder(final Engineer stakeHolder) {
    this.stakeHolder = stakeHolder;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrcl.engineerprocess.domain.impl.EngineerProjectImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) ){
    	hql += " and ((this.tscCostEstimation.requestInfo.projectName  LIKE :info) or (this.tscCostEstimation.project.name  LIKE :info))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getExcludedstatus()) ){
    	hql += " and ((this.Status) <> (:excludedstatus))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectManager()) ){
    	hql += " and ((this.projectManager) = (:projectManager))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStakeHolder()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStakeHolder()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStakeHolder()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStakeHolder()) ){
    	hql += " and (((((this.projectManager) = (:stakeHolder)) or ((this.techLeader) = (:stakeHolder))) or ((this.tscCostEstimation.technicalAssistant) = (:stakeHolder))) or ((this.tscCostEstimation.postSaleManager) = (:stakeHolder)))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo())){
    	query.setParameter("info",getInfo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getExcludedstatus())){
    	query.setParameter("excludedstatus",getExcludedstatus()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectManager())){
    	query.setParameter("projectManager",getProjectManager()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStakeHolder())){
    	query.setParameter("stakeHolder",getStakeHolder()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public EngineerProjectCriteriaImpl() {
    initOrderBys();
  }
}
